package com.lufei.dh;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.lufei.dh.ExList.ExListActivity;
import com.lufei.dh.Section.SectionActivity;
import com.lufei.dh.ShoppingCart.Card_Activity;
import com.lufei.dh.bottom.BottomActivity;
import com.lufei.dh.more.MoreActivity;
import com.lufei.dh.view.HDMain;
import com.lufei.dh.view.MapMain;
import com.lufei.dh.view.Mult.CateActivity;
import com.lufei.dh.view.book.CurlActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {
    String tag = "dhlog___";
    //声明AMapLocationClient类对象
    public AMapLocationClient mLocationClient = null;
    //声明定位回调监听器
    public AMapLocationListener mLocationListener = new AMapLocationListener() {
        @Override
        public void onLocationChanged(final AMapLocation aMapLocation) {
            Log.e(tag, aMapLocation.getAddress() + "________");
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    idMainText.setText(aMapLocation.getAddress());
                }
            });
        }
    };

    //声明AMapLocationClientOption对象
    public AMapLocationClientOption mLocationOption = null;
    @BindView(R.id.id_main_text)
    TextView idMainText;
    @BindView(R.id.id_main_btn1)
    Button idMainBtn1;
    @BindView(R.id.id_main_btn2)
    Button idMainBtn2;
    @BindView(R.id.id_main_btn3)
    Button idMainBtn3;
    @BindView(R.id.id_main_btn4)
    Button idMainBtn4;
    @BindView(R.id.id_main_btn5)
    Button idMainBtn5;
    @BindView(R.id.id_main_btn6)
    Button idMainBtn6;
    @BindView(R.id.id_main_btn7)
    Button idMainBtn7;
    @BindView(R.id.id_main_btn8)
    Button idMainBtn8;
    @BindView(R.id.id_main_btn9)
    Button idMainBtn9;
    @BindView(R.id.id_main_btn10)
    Button idMainBtn10;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        //初始化定位
        mLocationClient = new AMapLocationClient(getApplicationContext());
        //设置定位回调监听
        mLocationClient.setLocationListener(mLocationListener);

        //初始化AMapLocationClientOption对象
        mLocationOption = new AMapLocationClientOption();
        //获取一次定位结果：
        //该方法默认为false。
//        mLocationOption.setOnceLocation(true);


        //获取最近3s内精度最高的一次定位结果：
        //设置setOnceLocationLatest(boolean b)接口为true，
        // 启动定位时SDK会返回最近3s内精度最高的一次定位结果。
        // 如果设置其为true，setOnceLocation(boolean b)接口也会被设置为true，反之不会，默认为false。
        mLocationOption.setOnceLocationLatest(true);
        //设置定位间隔,单位毫秒,默认为2000ms，最低1000ms。
        mLocationOption.setInterval(1000);
        //设置是否返回地址信息（默认返回地址信息）
        mLocationOption.setNeedAddress(true);
        //设置是否允许模拟位置,默认为true，允许模拟位置
        mLocationOption.setMockEnable(true);


        //给定位客户端对象设置定位参数
        mLocationClient.setLocationOption(mLocationOption);
        //启动定位
//        mLocationClient.startLocation();

    }

    @OnClick({R.id.id_main_btn1, R.id.id_main_btn2, R.id.id_main_btn3, R.id.id_main_btn4, R.id.id_main_btn5, R.id.id_main_btn6, R.id.id_main_btn7, R.id.id_main_btn8, R.id.id_main_btn9
    ,R.id.id_main_btn10})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.id_main_btn1:
                startActivity(new Intent(MainActivity.this, MapMain.class));
                break;
            case R.id.id_main_btn2:
//                mLocationClient.stopLocation();
                startActivity(new Intent(MainActivity.this, com.lufei.dh.ExList.MainActivity.class));
                break;
            case R.id.id_main_btn3:

                startActivity(new Intent(MainActivity.this, HDMain.class));
                break;
            case R.id.id_main_btn4:
                startActivity(new Intent(MainActivity.this, Card_Activity.class));
                break;
            case R.id.id_main_btn5:
                startActivity(new Intent(MainActivity.this, ExListActivity.class));
                break;
            case R.id.id_main_btn6:
                startActivity(new Intent(MainActivity.this, SectionActivity.class));
                break;
            case R.id.id_main_btn7:
                startActivity(new Intent(MainActivity.this, MoreActivity.class));
                break;
            case R.id.id_main_btn8:
                startActivity(new Intent(MainActivity.this, BottomActivity.class));
                break;
            case R.id.id_main_btn9:
                startActivity(new Intent(MainActivity.this, CurlActivity.class));
                break;
            case R.id.id_main_btn10:
                startActivity(new Intent(MainActivity.this, CateActivity.class));

                break;
        }
    }
}
